﻿namespace NTLib.WPF.Themes
{
    using Application.Themes;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Collections;

    /// <summary>
    /// 
    /// </summary>
    /// <seealso cref="System.Collections.Generic.ICollection{NTLib.Application.Themes.IThemeDictionary}" />
    public class ThemeProxyCollection : ICollection<IResourceDictionary>
    {
        #region Fields

        private readonly ICollection<ResourceDictionary> _resources;

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the <see cref="ThemeProxyCollection"/> class.
        /// </summary>
        /// <param name="resources">The resources.</param>
        public ThemeProxyCollection(ICollection<ResourceDictionary> resources)
        {
            this._resources = resources;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        public int Count
        {
            get { return this._resources.Count; }
        }

        /// <summary>
        /// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.
        /// </summary>
        public bool IsReadOnly
        {
            get { return this._resources.IsReadOnly; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
        public void Add(IResourceDictionary item)
        {
            this._resources.Add(item as ResourceDictionary);
        }

        /// <summary>
        /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        public void Clear()
        {
            this._resources.Clear();
        }

        /// <summary>
        /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1" /> contains a specific value.
        /// </summary>
        /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
        /// <returns>
        /// true if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false.
        /// </returns>
        public bool Contains(IResourceDictionary item)
        {
            return this._resources.Contains(item as ResourceDictionary);
        }

        /// <summary>
        /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1" /> to an <see cref="T:System.Array" />, starting at a particular <see cref="T:System.Array" /> index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1" />. The <see cref="T:System.Array" /> must have zero-based indexing.</param>
        /// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param>
        public void CopyTo(IResourceDictionary[] array, int arrayIndex)
        {
            ResourceDictionary[] proxyArray = new ResourceDictionary[array.Length];
            this._resources.CopyTo(proxyArray, arrayIndex);

            for (int i = arrayIndex; i < array.Length; ++i)
                array[i] = proxyArray[i] as IResourceDictionary;
        }

        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// An enumerator that can be used to iterate through the collection.
        /// </returns>
        public IEnumerator<IResourceDictionary> GetEnumerator()
        {
            return this._resources.Cast<IResourceDictionary>().GetEnumerator();
        }

        /// <summary>
        /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
        /// <returns>
        /// true if <paramref name="item" /> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </returns>
        public bool Remove(IResourceDictionary item)
        {
           return this._resources.Remove(item as ResourceDictionary);
        }

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this._resources.GetEnumerator();
        }

        #endregion
    }
}
